package com.cslg.ac.demo.dao.pet;

import com.cslg.ac.demo.dao.pet.po.PetCommonPO;
import com.cslg.ac.demo.entity.pet.PetCommon;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PetCommonDAO {

    String TABLE_NAME = "e_pet_common";
    String INSERT_FILED = "(name,type,birthday,masterId,sterilize,kind,gender) ";
    String SET_FILED = "name,type,birthday,sterilize,kind,gender,image";
    String SELECT_FILED = "id,name,type,birthday,sterilize,gender,image";

    @Insert({"insert into",TABLE_NAME,INSERT_FILED,"values(#{name},#{type},#{birthday},#{masterId},#{sterilize},#{kind},#{gender})"})
    void insert(PetCommonPO pet);

    @Select({"select ",SELECT_FILED,"from ",TABLE_NAME,"where id = #{id}"})
    PetCommonPO selectById(@Param("id")int id);

    @Delete({"delete from ",TABLE_NAME,"where id = #{id}"})
    void delete(@Param("id")int id);

    @Update({"update",TABLE_NAME,"set name = #{name},type = #{type},birthday = #{birthday},sterilize = #{sterilize}," +
            "kind = #{kind},gender = #{gender},image = #{image} where id = #{id}"})
    void updateById(PetCommonPO petCommonPO);

    @Select({"select last_insert_id()"})
    int lastInsertId();

    @Select({"select id from ", TABLE_NAME, "where gender = #{gender} and kind = 1 order by id desc limit #{offset}, #{num}"})
    List<Integer> selectByGender(@Param("gender")int gender,@Param("offset")int offset, @Param("num")int num);


    @Select({"select id from ", TABLE_NAME, "where type = #{type} and kind = 1 order by id desc  limit #{offset}, #{num}"})
    List<Integer> selectByType(@Param("type")String type ,@Param("offset")int offset, @Param("num")int num);

    @Select({"select id from ", TABLE_NAME, "where gender = #{gender} and  type = #{type}  and kind = 1 order by id desc  limit #{offset}, #{num}"})
    List<Integer> selectByGenderAndType(@Param("gender")int gender, @Param("type")String type, @Param("offset")int offset, @Param("num")int num);



}
